const Router = require('koa-router')
const router = new Router({ prefix: '/' })
const u = require('../api')

router.get('/', async (ctx) => {
  ctx.response.status = 200
  ctx.config.nav[0].checked = true
  ctx.config.title = '达州市元翔职业技能培训学校有限公司_元翔官网'
  ctx.config.description = '达州市元翔职业技能培训学校有限公司，元翔官网'
  ctx.config.keyword = '达州元翔,元翔职校,职业培训,技能培训,培训学校,元翔官网,达州市元翔职业技能培训学校有限公司'
  // 元翔新闻
  let news1 = []
  let getNews1 = await u.getNewsList({
    category: 0,
    keyword: '',
    pageNum: 1,
    pageSize: 6
  })
  if (getNews1.errno == 0) {
    getNews1.result.list.forEach(item => {
      item.publishedTimeNow = item.publishedTime ? item.publishedTime.split(' ')[0] : ''
      item.href = `${ctx.config.host}/yxdt/${item.id}.html`
    })
    news1 = getNews1.result.list || []
  }
  // 行业动态
  let news2 = []
  let getNews2 = await u.getNewsList({
    category: 1,
    keyword: '',
    pageNum: 1,
    pageSize: 6
  })
  if (getNews2.errno == 0) {
    getNews2.result.list.forEach(item => {
      item.publishedTimeNow = item.publishedTime ? item.publishedTime.split(' ')[0] : ''
      item.href = `${ctx.config.host}/hydt/${item.id}.html`
    })
    news2 = getNews2.result.list || []
  }

  await ctx.render('index.ejs', {
    config: ctx.config,
    hotTab: [{
      id: 1,
      title: 'C1、C2驾驶培训',
      href: `${ctx.config.host}/jdcjspx/`
    }, {
      id: 2,
      title: 'B1、B2驾驶培训',
      href: `${ctx.config.host}/jdcjspx/`
    }, {
      id: 3,
      title: 'A1、A3驾驶培训',
      href: `${ctx.config.host}/jdcjspx/`
    }, {
      id: 4,
      title: 'A2驾驶培训',
      href: `${ctx.config.host}/jdcjspx/`
    }, {
      id: 5,
      title: '高、低压电工作业培训',
      href: `${ctx.config.host}/tzzypx/`
    }, {
      id: 6,
      title: '熔化焊接与热切割作业',
      href: `${ctx.config.host}/tzzypx/`
    }, {
      id: 7,
      title: '高处作业培训',
      href: `${ctx.config.host}/tzzypx/`
    }, {
      id: 8,
      title: '道路运输从业资格证',
      href: `${ctx.config.host}/dlyszgpx/`
    }],
    hotList: [{
      id: 1,
      title: 'C1、C2驾驶培训',
      src: `${ctx.config.host}/imgs/train1-1.jpg`,
      href: `${ctx.config.host}/jdcjspx/`
    }, {
      id: 2,
      title: 'B1、B2驾驶培训',
      src: `${ctx.config.host}/imgs/train1-2.jpg`,
      href: `${ctx.config.host}/jdcjspx/`
    }, {
      id: 3,
      title: 'A1、A3驾驶培训',
      src: `${ctx.config.host}/imgs/train1-3.jpg`,
      href: `${ctx.config.host}/jdcjspx/`
    }, {
      id: 4,
      title: '高、低压电工作业培训',
      src: `${ctx.config.host}/imgs/train2-1.jpg`,
      href: `${ctx.config.host}/tzzypx/`
    }, {
      id: 5,
      title: '熔化焊接与热切割作业',
      src: `${ctx.config.host}/imgs/train2-2.jpg`,
      href: `${ctx.config.host}/tzzypx/`
    }, {
      id: 6,
      title: '高处作业培训',
      src: `${ctx.config.host}/imgs/train2-3.jpg`,
      href: `${ctx.config.host}/tzzypx/`
    }],
    news1,
    news2
  })
})

module.exports = router